@extends('layout.master')

@section('title','游戏详情')

@section('css')
    @parent
    <link href="{{ asset('plugins/bower_components/summernote/dist/summernote.css') }}" rel="stylesheet"/>
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="white-box">
        <form class="form-horizontal form-material" method="post" enctype="multipart/form-data">
            <div class="row">
                <input type="hidden" name="id" id="id" value="{{ $game->id }}">
                <div class="col-md-6 col-sm-6">
                    <div class="form-group">
                        <label class="col-md-12">游戏名</label>
                        <div class="col-md-12">
                            <input type="text" name="name" id="name" value="{{ $game->name }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">总能量</label>
                        <div class="col-md-12">
                            <input type="text" name="sum_energy" id="sum-energy" value="{{ $game->sum_energy }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">本人每天培育次数</label>
                        <div class="col-md-12">
                            <input type="text" name="own_frequency" id="own-frequency"
                                   value="{{ $game->own_frequency }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">本人每次培育可增长能量</label>
                        <div class="col-md-12">
                            <input type="text" name="own_add_energy" id="own-add-energy"
                                   value="{{ $game->own_add_energy }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">未注册好友每天培育次数</label>
                        <div class="col-md-12">
                            <input type="text" name="old_friend_frequency" id="old-friend-frequency"
                                   value="{{ $game->old_friend_frequency }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">未注册好友每次培育可增长能量</label>
                        <div class="col-md-12">
                            <input type="text" name="old_friend_add_energy" id="old-friend-add-energy"
                                   value="{{ $game->old_friend_add_energy }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">注册好友每天培育次数</label>
                        <div class="col-md-12">
                            <input type="text" name="new_friend_frequency" id="new-friend-frequency"
                                   value="{{ $game->new_friend_frequency }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-2 col-sm-2">
                    <div class="form-group">
                        <label class="col-md-12">注册好友每次培育可增长能量</label>
                        <div class="col-md-12">
                            <input type="text" name="new_friend_add_energy" id="new-friend-add-energy"
                                   value="{{ $game->new_friend_add_energy }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <div class="form-group">
                        <label class="col-md-12">操作名</label>
                        <div class="col-md-12">
                            <input type="text" name="operating_name" id="operating-name"
                                   value="{{ $game->operating_name }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>

                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">游戏列表封面图</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="cover-img-url" class="dropify" name="cover_img_url"
                                   data-default-file="{{ $game->cover_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="cover" id="cover" value="{{ $game->cover_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">背景图</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="bg-img-url" class="dropify" name="bg_img_url"
                                   data-default-file="{{ $game->bg_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="bg" id="bg" value="{{ $game->bg_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">操作功能图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="operating-img-url" class="dropify" name="operating_img_url"
                                   data-default-file="{{ $game->operating_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="operating" id="operating" value="{{ $game->operating_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">第一层</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="floor-img-url" class="dropify" name="floor_img_url"
                                   data-default-file="{{ $game->floor_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="floor" id="floor" value="{{ $game->floor_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">第二层</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="front-img-url" class="dropify" name="front_img_url"
                                   data-default-file="{{ $game->front_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="front" id="front" value="{{ $game->front_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">浇水时的图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="click-img-url" class="dropify" name="click_img_url"
                                   data-default-file="{{ $game->click_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="click" id="click" value="{{ $game->click_img_url }}">
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <div class="form-group">
                        <label class="col-md-12">施肥需要耗费金币数</label>
                        <div class="col-md-12">
                            <input type="text" name="fertilization_cost_coin" id="fertilization-cost-coin"
                                   value="{{ $game->fertilization_cost_coin }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <div class="form-group">
                        <label class="col-md-12">施肥效果持续天数</label>
                        <div class="col-md-12">
                            <input type="text" name="fertilization_keep_days" id="fertilization-keep-days"
                                   value="{{ $game->fertilization_keep_days }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <div class="form-group">
                        <label class="col-md-12">施肥增加能量数</label>
                        <div class="col-md-12">
                            <input type="text" name="fertilization_energy" id="fertilization-energy"
                                   value="{{ $game->fertilization_energy }}"
                                   class="form-control form-control-line" required>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">施肥图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="fertilization-img-url" class="dropify" name="fertilization_img_url"
                                   data-default-file="{{ $game->fertilization_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="fertilization" id="fertilization" value="{{ $game->fertilization_img_url }}">
                        </div>
                    </div>
                </div>

                <div class="col-md-4 col-sm-4">
                    <label class="col-md-12">施肥操作图片</label>
                    <div class="col-md-12">
                        <div class="form-group ">
                            <input type="file" id="fertilization-click-img-url" class="dropify" name="fertilization_click_img_url"
                                   data-default-file="{{ $game->fertilization_click_img_url }}"
                                   data-height="200px"/>
                            <input type="hidden" name="fertilization_click" id="fertilization-click" value="{{ $game->fertilization_click_img_url }}">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <label class="col-md-12">游戏简介(ios)</label>
                <div class="col-md-12 col-sm-12">
                    <textarea name="contents" class="form-control" id="summernote" cols="30"
                              rows="5">{{ $game->ios_rule_description }}</textarea>
                </div>
            </div>
            <div class="row">
                <label class="col-md-12">游戏简介(android)</label>
                <div class="col-md-12 col-sm-12">
                    <textarea name="contents" class="form-control" id="summernote1" cols="30"
                              rows="5">{{ $game->android_rule_description }}</textarea>
                </div>
            </div>

        </form>
        <div class="form-group">
            <button class="fcbtn btn btn-success btn-outline btn-1e waves-effect" id="modify">修改
            </button>
            {!! csrf_field() !!}
            <a class="fcbtn btn btn-info btn-outline btn-1e waves-effect" href="{{ url('/game/list') }}">返回
            </a>

                <button class="fcbtn btn btn-success" id="del-flag">@if($game->del_flag === \App\Game::DEL_NO)下架@else上架@endif
                </button>
        </div>
    </div>

    <div class="panel">
        <div class="panel-heading">
            <div class="panel-action" style="margin-top: -9px">
                <a class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c"
                   href="{{ url('/game/status/publish') . '/' . $game->id }}">
                    <span>添加游戏状态</span>
                </a>
            </div>
        </div>
        <div class="panel-heading">游戏状态列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) . '/status' }}">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>状态名称</th>
                            <th>状态详情</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-heading">
            <div class="panel-action" style="margin-top: -9px">
                <a class="popup-with-form btn fcbtn btn btn-outline btn-info btn-1c"
                   href="{{ url('/game/commodity/publish') . '/' . $game->id }}">
                    <span>添加游戏奖励</span>
                </a>
            </div>
        </div>
        <div class="panel-heading">游戏奖励列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="game-comodity" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) . '/commodity' }}">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>状态名称</th>
                            <th>状态详情</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <script src="{{ asset('js/myself.js') }}"></script>

    <script>
        var obja = $('#game-comodity');
        var url = obja.data('url');
        obja.DataTable({
            dom: 'Bfrtip',
            buttons: [
                'copy', 'csv', 'excel', 'pdf', 'print'
            ],
            "ordering": true,
            "processing": true,
            "responsive": false,
            "lengthMenu": [
                [10, 20, 50, 100],
                ['10 行', '20 行', '50 行', '100 行']
            ],
            "order": [[0, "desc"]],
            "columnDefs": [{
                orderable: false,
                targets: [1, 2]
            }],
            "language": {
                "sProcessing": '<div id="fountainG"><div id="fountainG_1" class="fountainG"></div><div id="fountainG_2" class="fountainG"></div><div id="fountainG_3" class="fountainG"></div><div id="fountainG_4" class="fountainG"></div><div id="fountainG_5" class="fountainG"></div><div id="fountainG_6" class="fountainG"></div><div id="fountainG_7" class="fountainG"></div><div id="fountainG_8" class="fountainG"></div></div>',
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "暂无记录",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上一页",
                    "sNext": "下一页",
                    "sLast": "末页"
                }
            },
            serverSide: true,
            ajax: {
                url: url,
                type: 'POST',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            },
            "deferRender": true
        });
        $('.column_filter').on('change', function () {
            obja.DataTable().column($(this).data('column')).search($(this).val(), false, true).draw();
        });
        //跳转页
        obja.append("  到第 <input type='text' id='changePage1' class='input-text' style='width:50px;height:27px'> 页 ");
        var oTable = obja.dataTable();
        $('#changePage1').keyup(function (e) {
            if ($(this).val() && $(this).val() > 0) {
                var redirectpage = $(this).val() - 1;
            } else {
                redirectpage = 0;
            }
            oTable.fnPageChange(redirectpage);
        });


        $("#modify").click(function (e) {
            e.preventDefault();
            var id = $("#id").val();
            var name = $("#name").val();
            var sum_energy = $("#sum-energy").val();
            var own_frequency = $("#own-frequency").val();
            var own_add_energy = $("#own-add-energy").val();
            var old_friend_frequency = $("#old-friend-frequency").val();
            var old_friend_add_energy = $("#old-friend-add-energy").val();
            var new_friend_frequency = $("#new-friend-frequency").val();
            var new_friend_add_energy = $("#new-friend-add-energy").val();
            var fertilization_cost_coin = $("#fertilization-cost-coin").val();
            var fertilization_keep_days = $("#fertilization-keep-days").val();
            var fertilization_energy = $("#fertilization-energy").val();
            var ios_rule_description = $("#summernote").val();
            var android_rule_description = $("#summernote1").val();
            var operating_name = $("#operating-name").val();
            var cover_img = document.getElementById("cover-img-url").files;
            var bg_img = document.getElementById("bg-img-url").files;
            var operating_img = document.getElementById("operating-img-url").files;
            var floor_img = document.getElementById("floor-img-url").files;
            var front_img = document.getElementById("front-img-url").files;
            var click_img = document.getElementById("click-img-url").files;
            var fertilization_img = document.getElementById("fertilization-img-url").files;
            var fertilization_click_img = document.getElementById("fertilization-click-img-url").files;
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    if (cover_img.length) {
                        if ((cover_img[0].type).indexOf("image/") === -1) {
                            swal("请上传封面图片!");
                            return false;
                        }
                        var cover_img_url = picajax(cover_img[0]);
                    } else {
                        cover_img_url = $("#cover").val();
                    }


                    if (bg_img.length) {
                        if ((bg_img[0].type).indexOf("image/") === -1) {
                            swal("请上传背景图片!");
                            return false;
                        }
                        var bg_img_url = picajax(bg_img[0]);
                    } else {
                        bg_img_url = $("#bg").val();
                    }


                    if (operating_img.length) {
                        if ((operating_img[0].type).indexOf("image/") === -1) {
                            swal("请上传操作功能图片!");
                            return false;
                        }
                        var operating_img_url = picajax(operating_img[0]);
                    } else {
                        operating_img_url = $("#operating").val();
                    }

                    if (floor_img.length) {
                        if ((floor_img[0].type).indexOf("image/") === -1) {
                            swal("请上传第二层图片!");
                            return false;
                        }
                        var floor_img_url = picajax(floor_img[0]);
                    } else {
                        floor_img_url = $("#floor").val();
                    }
                    if (front_img.length) {
                        if ((front_img[0].type).indexOf("image/") === -1) {
                            swal("请上传第三层图片!");
                            return false;
                        }
                        var front_img_url = picajax(front_img[0]);
                    } else {
                        front_img_url = $("#front").val();
                    }
                    if (click_img.length) {
                        if ((click_img[0].type).indexOf("image/") === -1) {
                            swal("请上传浇水时图片!");
                            return false;
                        }
                        var click_img_url = picajax(click_img[0]);
                    } else {
                        click_img_url = $("#floor").val();
                    }

                    if (fertilization_img.length) {
                        if ((fertilization_img[0].type).indexOf("image/") === -1) {
                            swal("请上传施肥图片!");
                            return false;
                        }
                        var fertilization_img_url = picajax(fertilization_img[0]);
                    } else {
                        fertilization_img_url = $("#fertilization").val();
                    }

                    if (fertilization_click_img.length) {
                        if ((fertilization_click_img[0].type).indexOf("image/") === -1) {
                            swal("请上传施肥操作图片!");
                            return false;
                        }
                        var fertilization_click_img_url = picajax(fertilization_click_img[0]);
                    } else {
                        fertilization_click_img_url = $("#fertilization-click").val();
                    }
                    $.ajax({

                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/game/gameInfo/" + id,
                        type: "POST",
                        data: {
                            name: name,
                            sum_energy: sum_energy,
                            own_frequency: own_frequency,
                            own_add_energy: own_add_energy,
                            old_friend_frequency: old_friend_frequency,
                            old_friend_add_energy: old_friend_add_energy,
                            new_friend_frequency: new_friend_frequency,
                            ios_rule_description: ios_rule_description,
                            android_rule_description: android_rule_description,
                            operating_name: operating_name,
                            new_friend_add_energy: new_friend_add_energy,
                            fertilization_cost_coin: fertilization_cost_coin,
                            fertilization_keep_days: fertilization_keep_days,
                            fertilization_energy: fertilization_energy,
                            cover_img_url: cover_img_url,
                            bg_img_url: bg_img_url,
                            floor_img_url: floor_img_url,
                            front_img_url: front_img_url,
                            click_img_url: click_img_url,
                            fertilization_img_url: fertilization_img_url,
                            fertilization_click_img_url: fertilization_click_img_url,
                            operating_img_url: operating_img_url
                        },
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },

                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            } else {
                                swal(data.message);
                            }
                        }
                    })
                }
            );
        });

        $("#del-flag").click(function (e) {
            e.preventDefault();
            var id = $("#id").val();
            swal({
                    title: "",
                    text: "确定修改么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({

                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: "/game/gameDelflag/" + id,
                        type: "POST",
                        error: function (e) {
                            if (e.readyState === 4 && e.status === 422) {
                                for (var i in e.responseJSON) {
                                    if (e.responseJSON[i] !== 'The given data was invalid.') {
                                        err = e.responseJSON[i];
                                        for (var j in err) {
                                            toasterror(err[j][0]);
                                        }
                                    }
                                }
                            }
                        },

                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message, '', 'success');
                                swal(data.message);
                            } else {
                                $('.confirm').click(function () {
                                    location.reload();
                                });

                            }
                        }
                    })
                }
            );
        });


        obj.on('click', '.btn-status-del', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定删除么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/game/status/del/' + id,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        obja.on('click', '.btn-commodity-del', function () {
            var id = $(this).data('id');
            swal({
                    title: "",
                    text: "确定删除么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/game/commodity/del/' + id,
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });
    </script>
@endsection